package org.tank.strategy;

import org.tank.Tank;

import java.util.Arrays;
import java.util.Comparator;

public  class    Main<T>  {


    public void sort(T  [] arr, Comparator<T> comparator){
        for (int i = 0; i <arr.length-1; i++) {
            for (int j = 1; j <arr.length-i; j++) {
                T temp=arr[j];
            if(comparator.compare(arr[j-1],arr[j])>0){
                arr[j]=arr[j-1];
                arr[j-1]=temp;
            }

          /*   if(arr[j-1]>arr[j]){
                 arr[j]=arr[j-1];
                 arr[j-1]=temp;
             }*/
            }
        }
    }


    public static void main(String[] args) {
//        int [] arr=new int[]{100,9,4,90,100,11,111,111,222,333,444};
//        new Main<>().sort(arr,null);
//        System.out.println(Arrays.toString(arr));


        Cat[] arr=new Cat[]{new Cat(1),new Cat(3),new Cat(2)};

        new Main<Cat>().sort(arr, new Comparator<Cat>() {
            @Override
            public int compare(Cat o1, Cat o2) {
                return o1.getHeight()-o2.getHeight();
            }
        });



        Dog[] dog=new Dog[]{new Dog(100),new Dog(3),new Dog(1)};

        new Main<Dog>().sort(dog, (x,y)->x.getFood()-y.getFood());

                System.out.println(Arrays.toString(dog));
    }
}
